From 6a6ea8c94e1622738ff05c9e4676a462b96192a3 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Fri, 29 Sep 2006 11:26:33 +0100 Subject: [PATCH] [HVM][VMX] Clear vmxe when VMX is not enabled. The current Xen code keeps X86_CR4_VMXE set even if VMXON has not been executed. The stop_vmx() code assumes that it is possible to call VMXOFF if X86_CR4_VMXE is set which is not always true. Calling VMXOFF without VMXON results in an illegal opcode trap, and to avoid this condition this patch makes sure that X86_CR4_VMXE is only set when VMXON has been called. Tested using x86_32 on a Pentium D 930. Signed-Off-By: Magnus Damm --- xen/arch/x86/hvm/vmx/vmx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index d22e158224..8b162d75a9 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -485,8 +485,10 @@ static void vmx_ctxt_switch_to(struct vcpu *v) static void stop_vmx(void) { - if (read_cr4() & X86_CR4_VMXE) - __vmxoff(); + if ( !(read_cr4() & X86_CR4_VMXE) ) + return; + __vmxoff(); + clear_in_cr4(X86_CR4_VMXE); } void vmx_migrate_timers(struct vcpu *v) @@ -806,12 +808,14 @@ int start_vmx(void) if ( (vmcs = vmx_alloc_host_vmcs()) == NULL ) { + clear_in_cr4(X86_CR4_VMXE); printk("Failed to allocate host VMCS\n"); return 0; } if ( __vmxon(virt_to_maddr(vmcs)) ) { + clear_in_cr4(X86_CR4_VMXE); printk("VMXON failed\n"); vmx_free_host_vmcs(vmcs); return 0; -- 2.30.2